<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mdl_team extends CI_Model {
	function __construct() {
		parent::__construct();
	}

	function get_table() {
		$table = "Events";

		return $table;
	}

	//we also can do
	//var $table = "dfasfs";
	//and inside each function, we will change $table by $this->table

	function get($order_by) {
		$table = $this->get_table();

		$this->db->order_by($order_by);
		$query = $this->db->get($table);

		return $query;
	}

	function get_with_limit($limit, $offset, $order_by) {
		$table = $this->get_table();
		$this->db->limit($limit, $offset);
		$this->db->order_by($order_by);
		$query = $this->db->query($table);

		return $query;
	}

	function get_where($id) {
		$table = $this->get_table();
		$this->db->where('id', $id);
		$query = $this->db->get($table);

		return $query;
	}

	function get_where_custom($col, $value) {
		$table = $this->get_table();
		$this->db->where($col, $value);
		$query = $this->db->get($table);

		return $query;
	}

	function _insert($data) {
		$table = $this->get_table();
		$this->db->insert($table, $data);
	}

	function _update($id, $data) {
		$table = $this->get_table();
		$this->db->where('id', $id);
		$this->db->update($table, $data);
	}

	function _delete($id) {
		$table = $this->get_table();
		$this->db->where('id', $id);
		$this->db->delete($table);
	}

	function count_where($column, $value) {
		$table = $this->get_table();
		$this->db->where($column, $value);
		$query = $this->db->get($table);
		$num_rows = $query->num_rows();
		return $num_rows;
	}

	function count_all() {
		$table = $this->get_table();
		$query = $this->db->get($table);
		$num_rows = $query->num_rows();

		return $num_rows;
	}

	function get_max() {
		$table = $this->get_table();
		$this->db->select_max('id');
		$query = $this->db->get($table);
		$row = $query->row();
		$id = $row->id;
		return $id;
	}

	function _custom_query($mysql_query) {
		$query = $this->db->query($mysql_query);
		return $query;
	}

	function getOurTeam($id, $lang_id, $market) {
		$this->db->select('p.Post_ID,pt.Title,pt.Summary,pt.PostContent,p.ImageUrl,p.FileUrl,p.Published,p.SortOrder');
		$this->db->from('dbo.Posts p');
		$this->db->join('dbo.PostCategories pc', 'pc.Category_ID = p.CategoryFID');
		$this->db->join('dbo.PostTranslation pt', 'pt.PostFID = p.Post_ID');

		if(isset($id) && !empty($id)) {
			$where = array(
	        	'p.Post_ID'		 => $id,
	        	'pc.Category_ID' => 5, 	
	        	'pt.LanguageFID' => $lang_id,
	        	'p.Published'    => 1,
	        	'p.MarketFID'	 => $this->db->escape_str($market)
			);
			 
			$this->db->where($where);

			$query = $this->db->get();

			if ($query->num_rows() > 0) {
				return $query->row();
			} else {
				return false;
			}
			 
		} else {
			$where = array(
	        	'pc.Category_ID' => 5, 	
	        	'pt.LanguageFID' => $lang_id,
	        	'p.Published'    => 1,
	        	'p.MarketFID'	 => $this->db->escape_str($market)
			);
			 
			$this->db->where($where);
			
			$this->db->order_by('p.SortOrder ASC');

			$query = $this->db->get();

			if ($query->num_rows() > 0) {
				return $query->result();
			} else {
				return false;
			}
		}
	}

	function getEventsImage($id) {
		$this->db->select('FileName, Extension');
		$this->db->from('EventFiles');
		$where = array(
        	'EventFID' 	=>	$id
		);

		$this->db->where($where);

		$query = $this->db->get();

		$arr = array();

		if ($query->num_rows() > 0) {
			foreach ($query->result() as $row) {
				array_push($arr, $row);
			}
			return $arr;
		} else {
			return false;
		}
	}
}

?>
